//
//  HYHomeMainView.m
//  XPlayer
//
//  Created by liguoqing on 2023/11/6.
//

#import "HYHomeMainView.h"
#import "HYHomeListView.h"
#import "HYHomeCollectionView.h"
#import "HYBDpanListView.h"
#import "HYBDPanCollectionView.h"

@interface HYHomeMainView ()

@property (nonatomic, strong) NSString *placeTitle;

@property (nonatomic, strong) HYHomeListView *tableView;

@property (nonatomic, strong) HYHomeCollectionView *collectionView;

@property (nonatomic, strong) HYBDpanListView *bdListView;

@property (nonatomic, strong) HYBDPanCollectionView *bdCcollectionView;

@end

@implementation HYHomeMainView

- (instancetype)initWithViewModel:(HYHomeViewModel *)viewModel fileType:(HYHomeFileType)fileType
{
    self = [super init];
    if(self){
        self.viewModel = viewModel;
        self.fileType = fileType;
        if(viewModel.parentPath.length || viewModel.folderPath.length){// 文件导入
            self.placeTitle = NSLocalizedString(@"还没有文件\n赶紧试试上传吧", nil);
        }else{
            self.placeTitle = NSLocalizedString(@"还没有文件\n点击加号试试新建文件吧", nil);
        }
        [self configUI];
    }
    return self;
}

- (instancetype)initWithBDViewModel:(HYBDPanFileListViewModel *)bdPanviewModel fileType:(BDPanFileType)bdFileType
{
    self = [super init];
    if(self){
        self.bdPanviewModel = bdPanviewModel;
        self.bdFiletype = bdFileType;
        [self configBDUI];
    }
    return self;
}

- (void)configUI
{
    [self addEmptyViewWithPlaceImageName:@"icon_empty_place" placeTitle:self.placeTitle];
    HYLayoutType layoutType = [HYMineSetManager shareManager].layoutType;
    if(!layoutType){
        if(_collectionView){
            [self.collectionView removeFromSuperview];
            self.collectionView = nil;
        }
        [self addSubview:self.tableView];
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }else{
        if(_tableView){
            [self.tableView removeFromSuperview];
            self.tableView = nil;
        }
        [self addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
}
- (void)configBDUI
{
    HYLayoutType layoutType = [HYMineSetManager shareManager].layoutType;
    if(!layoutType){
        if(_bdCcollectionView){
            [self.bdCcollectionView removeFromSuperview];
            self.bdCcollectionView = nil;
        }
        [self addSubview:self.bdListView];
        [self.bdListView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }else{
        if(_bdListView){
            [self.bdListView removeFromSuperview];
            self.bdListView = nil;
        }
        [self addSubview:self.bdCcollectionView];
        [self.bdCcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
}
- (void)refreshLayoutType
{
    [self configUI];
}

#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView 
{
    return self;
}

#pragma mark - loadLazy
- (HYHomeListView *)tableView
{
    if(!_tableView){
        _tableView = [[HYHomeListView alloc]initWithViewModel:self.viewModel fileType:self.fileType];
    }
    return _tableView;
}

- (HYHomeCollectionView *)collectionView
{
    if(!_collectionView){
        _collectionView = [[HYHomeCollectionView alloc]initWithViewModel:self.viewModel fileType:self.fileType];
    }
    return _collectionView;
}

- (HYBDpanListView *)bdListView
{
    if (_bdListView == nil) {
        _bdListView = [[HYBDpanListView alloc]initWithViewModel:self.bdPanviewModel fileType:self.bdFiletype];
    }
    return _bdListView;
}

- (HYBDPanCollectionView *)bdCcollectionView
{
    if(_bdCcollectionView == nil){
       _bdCcollectionView = [[HYBDPanCollectionView alloc]initWithViewModel:self.bdPanviewModel fileType:self.bdFiletype];
    }
    return _bdCcollectionView;
}
@end
